home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
146_01
/
notes.doc
< prev
next >
Wrap
Text File
|
1985-03-09
|
22KB
|
730 lines
/*
HEADER: CUG146.10;
TITLE: A letter from Serge Stepanoff;
KEYWORDS: Serge Stepanoff, Small-C, Ron Cain;
SYSTEM: FLEX;
FILENAME: NOTES.DOC;
AUTHORS: Serge Stepanoff, Ron Cain;
COMPILERS: Small-C;
*/
Serge Stepanoff
5469 Arlene Way
Livermore, CA 94550
INTRODUCTION:
Small-C is exactly what the name implies -- a subset of the language C
developed at Bell Labs and best described in the de-facto language definition
"The C Programming Language", by Brian Kernighan and Dennis Ritchie, published
by Prentice-Hall, Inc. 1978.
The original Small-C compiler was written by Ron Cain for the 8080
microcomputer on a North Star system. He was kind and farsighted enough to
place it in the public domain via articles in "Dr. Dobbs Journal". Since
then, this compiler has been adapted to several operating systems and
microcomputers, including the 6809. To this author's knowledge, this is the
first adaptation for the 6800 micro under TSC's FLEX operating system. The
project required approximately one year's worth of calendar time, mainly
because the work on it was carried out in a sporadic and aperiodic basis.
Initial conversion attempts involved compilation directly to assembly level
code, but this approach was quickly dropped due to lack of any 16 bit
arithmetic in the 6800 instruction set and general paucity of stack
operations. Resultant code was lengthy to say the least -- no wonder the 6809
came about. However, in the tradition of PASCAL's P-code and FORTH's threaded
code, a solution was found in translating to a pseudo-code and then
interpreting this code on a virtual machine. The penalty in execution time is
much less than for a straight interpreter ala BASIC -- the pseudo-code
interpreter and the run-time library occupy less than 2K bytes, and as an
interesting side note, to execute this pseudo-code on a different operating
system or a different micro- computer requires only the rewrite of the
interpreter and the run-time library for the target machine.
As a historical note, the initial conversion was not done on a UNIX system,
but rather on a PDP 11 running RSX-11 operating system and the DECUS version
of a C compiler (another public-domain User Group product) with the Small-C
code supplied by DECUS (Digital Equipment Corporation Users Society). The
ongoing development of this version of the Small-C compiler is being carried
out on a SWTPC 6800 system with dual 8 inch single density floppy drives, and
32K of RAM memory.
- 1 -
SMALL-C USER NOTES. Page 2
OPERATION:
The Small-C compiler is invoked by typing CC on the keyboard. No command line
arguments are necessary. A series of questions are then asked. After each
question, Small-C prints (in paretheses) what the possible responses are. The
capitalized response is the one that Small-C will default to if you just press
RETURN. The first question is:
Do you want the c-text to appear (y,N) ?
This gives you the option of interleaving the source code into the output
file. Response is Y or N (y or n will also serve). If Y is given, an
asterisk will be placed at the start of each input line (to force a comment to
the 6800 assembler) and the input lines will be interleaved with the compiler
generated pseudo-code output. If the answer is N (or just RETURN, since N is
capitalized, and is the default), only the generated pseudo-code will be
output. NOTE: the TSC assembler accepts any length labels, both lower and
upper case, but only the first 6 characters are used and saved in the symbol
table. Therefore, if you have either functions or labels of the type MODULE1
and MODULE2, the assembler will generate a multiply defined label error. So,
make sure that the first 6 characters are unique. C'est la vie.....
Are you compiling the whole program at once (Y,n) ?
This is a convenience (or annoyance) question. If you type Y (or RETURN), you
will be able to avoid three more technical questions, which are only needed if
your C program will be fed into Small-C in several separate compilations.
(Best not to do it.)
If you answer N to the all-at-once question, you'll also be asked:
Do you want the globals to be defined (y,N) ?
This question is primarily a developmental aid between machines. If the
answer is Y, all static symbols will allocate storage within the module
being compiled. This is the normal method. If N (or RETURN), no storage
will be allocated, but symbol references will still be made in the normal
way. Essentially, this question allows the user to specify all or none
of the static symbols 'external'.
Is the output file the first one the assembler will see (y,N) ?
If it is, Small-C will put out a short prologue that parses the command
line parameters (if any), sets up the stack, and calls the C program as a
subroutine, so that a return to FLEX may be made properly when the
routine is finished.
Starting number for labels (0) ?
This lets you supply the first label number generated by the compiler for
its internal labels (which will typically be "ccNNN", where "NNN" is a
decimal number). This option allows modules to be compiled separately
and later appended on the source level without generating multi-defined
- 2 -
SMALL-C USER NOTES. Page 3
labels. If you just press RETURN, labels will start at "cc000".
Now a question that requires some consideration:
Should I pause after an error (y,N) ?
If your are doing a long compilation, the sort that you go off and mow the
lawn during, you run the risk of having an error message scroll off the screen
while you're away. If you answer Y to this question, Small-C will, when it
finds an error, stop everything it's doing until you tell it to proceed. That
way, you are assurred of knowing about ALL the errors that the compiler found.
FLEX users have a third choice -- set the TTYSET screen full Pause parameter
to YES. This will stop any tendency to scroll off important messages at the
expense of having to hit ESCAPE every time the screen prints the maximum
number of lines.
Output filename ?
This question gets the name of the file to be created. If you press RETURN,
the output of the compiler will go to the screen. Doing this, especially in
conjunction with having the C source code interleaved with the normal output,
is one way of learning what the compiler does with your source.
CAUTION !!!! If the output file already exists, the compiler will delete it
with NO warning to you -- which makes for frustration at least when you meant
to type in FILE.A and instead typed FILE.C.... If this worries you, modify the
run-time routine "fopen" in the interpreter.
Input filename ?
This question gets the name of the C source module to use as input. The
question will be repeated each time a name is supplied, allowing the user to
create an output file consisting of many separate files. (It behaves as if
you had appended them together and submitted only the one file.) Press RETURN
to end the compilation process. Again CAUTION!!!, if you mistype the file
name and the file is not found, the compiler will exit to FLEX after
appropriate message. If this annoys you go fix "fopen".
Here is how you would compile the sample program "WC.C":
+++CC [invoke the compiler]
* * * greetings and
salutations with a note
for the sponsor